<template>
	<div>
		<h2 style="color: red; text-align: center;margin-bottom: 10px;">此页面信息提交后不可修改，请谨慎填写</h2>
		<Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
		    <FormItem label="姓名" prop="USER_NAME">
		        <Input v-model="formValidate.USER_NAME" readonly placeholder="请输入您的真实姓名"></Input>
		    </FormItem>
			
			
			<FormItem label="所属学院" prop="name1">
			  <Select v-model="coid" style="width:200px"  @on-open-change="onOpenChangeCollege" @on-change="onOpenChangeMajor" clearable >
			    <Option v-for="item in collegeList" :value="item.id" :key="item.id">
			      {{ item.name }}
			    </Option>
			  </Select>
			</FormItem>
			<FormItem label="所属专业" prop="name2">
			  <Select v-model="mid" style="width:200px"  @on-change="onOpenFindClassByMid" clearable >
			    <Option v-for="item in majorList" :value="item.id" :key="item.id">
			      {{ item.name }}
			    </Option>
			  </Select>
			</FormItem>
			<FormItem label="所属班级" prop="name3">
			  <Select v-model="formValidate.c_id"  style="width:200px" clearable >
			    <Option v-for="item in classList" :value="item.id" :key="item.id">
			      {{ item.name }}
			    </Option>
			  </Select>
			</FormItem>
			<FormItem label="性别">
			            <RadioGroup v-model="formValidate.sex">
			                <Radio label="男">男</Radio>
			                <Radio label="女">女</Radio>
			            </RadioGroup>
			</FormItem>
		    <FormItem label="学号" prop="student_number">
		        <Input v-model="formValidate.student_number" readonly placeholder="请输入您的学号"></Input>
		    </FormItem>
			<FormItem label="手机号" prop="telphone">
			    <Input v-model="formValidate.telphone" readonly placeholder="请输入您的手机号"></Input>
			</FormItem>
		    <FormItem label="身份证号" prop="id_card">
		        <Input v-model="formValidate.id_card" readonly placeholder="请输入您的身份证号"></Input>
		    </FormItem>
		    <FormItem label="籍贯" prop="native_place">
		        <Input v-model="formValidate.native_place" placeholder="请输入籍贯"></Input>
		    </FormItem>
		    <FormItem label="现租住地址" prop="now_place">
		        <Input v-model="formValidate.now_place" placeholder="请输入现居住地址"></Input>
		    </FormItem>
		    
		    <FormItem>
		        <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
		        <Button @click="handleReset('formValidate')" style="margin-left: 8px">重置</Button>
		    </FormItem>
		</Form>
		
	</div>
</template>

<script>
	import {saveInfo, userInfoLogind, userInfoVerifyRepetition} from '@/api/lky/lkyStudent'
	import {createFormObj, createModelObj, getToken} from '@/libs/util'
	import {queryAll} from '@/api/lky/lkyCollege'
	import {queryAllM} from '@/api/lky/lkyMajor'
	import {queryFindClassByMid, queryFindClassMajorCollegeListByTid} from '@/api/lky/lkyClass'
	
	export default {
	    data () {
	        return {
				coid: '',
				mid: '',
				collegeList: [],
				majorList: [],
				classList: [],
				   //已选中的班级
				// 存放老师id，班级ids
				userInfo: {
					ID:''
				},
				formTeacherClass: {
				  id: ''
				},
	            formValidate: {
	                USER_NAME: '',
					sex:'',
	                telphone: '',
	                student_number: '',
	                id_card: '',
	                native_place: '',
					now_place:'',
					c_id: ''
	            },
				rePassword: {
					REPASSWD: ''
				},
	            ruleValidate: {
	                USER_NAME: [
	                    { required: true, message: '名字不能为空', trigger: 'blur' }
	                ],
	                telphone: [
	                    { required: true, message: '手机号不能为空', trigger: 'blur' },
	                ],
	                student_number: [
	                    { required: true, message: '学好不能为空', trigger: 'blur' }
	                ],
	                id_card: [
	                    { required: true, message: '身份证号不能为空', trigger: 'blur' }
	                ],
					native_place: [
					    { required: true, message: '籍贯不能为空', trigger: 'blur' }
					],
					now_place: [
					    { required: true, message: '现租住地址不能为空', trigger: 'blur' }
					],
					c_id: [
					    { required: true, message: '必须选择班级', trigger: 'blur' }
					]
	            }
	        }
	    },
		mounted:function(){
		      this.user_info();//需要触发的函数
		    },
	    methods: {
			//获取当前登陆用户的信息
			user_info(){
				
				this.userInfo.ID=getToken();
				
				userInfoLogind(Object.assign({}, createModelObj(this.userInfo, 'user'))).then(
				  res => {
				    if (res) {
					  this.formValidate.USER_NAME=res.data[0].USER_NAME
					  this.formValidate.telphone=res.data[0].telphone
					  this.formValidate.student_number=res.data[0].USER_CODE
					  this.formValidate.id_card=res.data[0].id_card
				    }
				  }
				)
			},
			onOpenChangeCollege () {
			    queryAll().then(res => {
			      this.collegeList = res.data
			    })
			  },
			  onOpenChangeMajor (coid) {
			    queryAllM({'coid': this.coid}).then(res => {
			      this.majorList = JSON.parse(JSON.stringify(res.data))
			    })
			  },
			  onOpenFindClassByMid (mid) {
			    queryFindClassByMid({'mid': this.mid}).then(res => {
			      this.classList = JSON.parse(JSON.stringify(res.data))
			    })
			  },
			  // 查询班级列表
			  queryFindClassMajorCollegeListByTid (tid) {
			    queryFindClassMajorCollegeListByTid({'tid': this.formTeacherClass.id}).then(res => {
			      this.classTeacherList = JSON.parse(JSON.stringify(res.data))
			    })
			  },
			  handleSubmit (name) {

				  userInfoVerifyRepetition({'student_number': this.formValidate.student_number}).then(res => {
					  res=res.toString()
					  if(res!=='1'){
						  alert("请勿重复提交")
					  }else{
						 this.$refs[name].validate((valid) => {
							 if(valid){
								 saveInfo(Object.assign({}, createModelObj(this.formValidate, 'student'))).then(
								   res => {
								     if (res) {
								       this.$emit('addRow', res.row)
								       this.$emit('input', false)
								       this.handleReset(name)
								     }
								   }
								 )
							 }
						 					  
						 }) 
						  
					  }
				  }) 
					  
				  
			  }
			},
			watch: {
			  value: function (val, oldVal) {
			    this.$refs.formTeacherClass.resetFields()
			    // console.log("22===========")
			    // console.log(this.formTeacherClass)
			    coverFormProps(this.formTeacherClass, this.lkyTeacher)
			    // console.log("333====")
			    // console.log(this.lkyTeacher)
			    // console.log(this.formTeacherClass)
			  },
			  // 获取学院id
			  lkyTeacher(n){
			    if(n!=null){
			      // console.log("n========n")
			      // console.log(n)
			      // this.coid = n.id2
			      // this.formLkyClass.mid = n.mid
			      // this.onOpenChangeMajor()
			    }
			  }
			}
	    }
	
	

	
</script>

<style>
</style>
